# 选择结构
# if、else、elif

# 输入一个年龄，判断是不是成年
# str1 = input("请输入一个年龄：")
# age = int(str1)
age = 18
'''
Java
if (表达式){
    表达式满足则执行
}

Python
if 表达式 :
....表达式满足则执行

'''

if age < 0 or age > 200:
    print("外星人")
elif age >= 18:
    print("成年")
else:
    print("未成年")

# 循环结构
# while循环
"""
while 表达式:
....表达式成立则执行循环
....表达式成立则执行循环
....表达式成立则执行循环
"""

# 计算1-100的和
sum = 0
i = 1
while i <= 100:
    sum += i
    i += 1
print(sum)

# 计算10的阶乘
result = 1
i = 10
while i >= 1:
    result *= i
    i -= 1
print(result)

# 计算1-10的奇数的和
sum = 0
i = 1
while i <= 100:
    if i % 2 == 0:
        i += 1
        continue
    if i == 11:
        break
    sum += i
    i += 1
print(sum)

# for 循环
# 一般不用于做循环操作，一般用于遍历数据容器
# 遍历list
list1 = [1, 2, 3, 4, 5]
for jk in list1:
    print(jk)

# 遍历tuple
tuple1 = (1, 2, 3, 4)
for q in tuple1:
    print(q)

# 遍历set
set1 = {1, 2, 3, 3, 3, 3, 4, 4}
for s in set1:
    print(s)

# 遍历dict
dict1 = {
    "k1": "v1",
    "k2": "v2",
    "k3": "v3"
}

# 直接遍历 只能获取key
for key in dict1:
    print(key)
    # 直接通过key提取value
    print(dict1[key])

# 使用items()方法
for k, v in dict1.items():
    print(k, type(k))
    print(v, type(v))

# zip()
ids = [1, 2, 3, 4, 5]
scores = [100, 90, 99, 88, 70]
for id, score in zip(ids, scores):
    print(id, type(id))
    print(score, type(score))

# enumerate()
# 给每个元素加上索引
for i, j in enumerate(scores):
    print(i, j, type(i), type(j))

# 列表推导式
# 1~10的奇数的list
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
list2 = [1, 3, 5, 7, 9]

# 1~100的list
# range(起始值,结束值,步长)
list3 = []
for i in range(1, 101, 1):
    print(i)
    list3.append(i)
print(list3)

list3_1 = [i for i in range(1, 101, 1) if i % 2 == 1]
print(list3_1)

# 9 9 乘法表
list4 = [str(i) for i in range(1, 11, 1) if i % 2 == 1]
print(list4)
print("#".join(list4))
# {} * {} = {}
format1 = "{} * {} = {}"
list5 = ["\t".join([format1.format(i, j, i * j) for j in range(1, i + 1)]) for i in range(1, 10)]
for l in list5:
    print(l)
print(list5)

print("\n".join(["\t".join(["{} * {} = {}".format(i, j, i * j) for j in range(1, i + 1)]) for i in range(1, 10)]))
